﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;

public partial class Controls_myAnnunciAuto : System.Web.UI.UserControl
{
    public string Tabella { get; set; }
    public string SelectedID { get; set; }
    protected MetaTable table;

    protected void Page_Init(object sender, EventArgs e)
    {
        var t = Tabella;
        this.DetailsDataSource_myAnnAuto.EntitySetName = "ANNVendita";
        DynamicDataManager1.RegisterControl(this.FormView1, false);
    }//fM

    protected void Page_Load(object sender, EventArgs e)
    {
        //this.DetailsDataSource.EntitySetName = Tabella;
        table = this.DetailsDataSource_myAnnAuto.GetTable();
        //Title = table.DisplayName;
        //this.DetailsDataSource.CommandText = "ANNVendita";
        this.DetailsDataSource_myAnnAuto.Include = table.ForeignKeyColumnsNames;

    }//fM

    public void ShowDettagli(int pID, FormViewMode pModo)
    {
        //this.DetailsDataSource.EntitySetName = pTabella ;
        this.FormView1.DefaultMode = pModo;
        this.DetailsDataSource_myAnnAuto.AutoGenerateWhereClause = false;
        this.DetailsDataSource_myAnnAuto.WhereParameters["ID"].DefaultValue = pID.ToString();
        this.DetailsDataSource_myAnnAuto.DataBind();

        if (pModo == FormViewMode.ReadOnly)
            this.myLiteralTitle.Text = "Dettagli annuncio / Details ";
        else
            this.myLiteralTitle.Text = "Modifica annuncio / Update ";

    }//fM

    public void NuovoAnnuncio()
    {
        this.FormView1.DefaultMode = FormViewMode.Insert;
        this.DetailsDataSource_myAnnAuto.WhereParameters["ID"].DefaultValue = "0";
        this.DetailsDataSource_myAnnAuto.DataBind();
        this.FormView1.DataBind();

        this.myLiteralTitle.Text = "Nuovo annuncio / New ";
    }



    protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == DataControlCommands.CancelCommandName)
        {
            //Response.Redirect(table.ListActionPath);
        }
    }

    protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        if (e.Exception == null || e.ExceptionHandled)
        {
            //Response.Redirect(table.ListActionPath);
        }
    }//fM



    protected void ListView1_ItemInserted(object sender, ListViewInsertedEventArgs e)
    {
        if (e.Exception != null)
        {

        }
        if (e.AffectedRows == 1)
        {
            //Ok
        }
    }//fM

    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        var dati = e.Values;
    }

    protected void DetailsDataSource_Inserting(object sender, EntityDataSourceChangingEventArgs e)
    {
        var ex = e.Exception;
    }
    protected void DetailsDataSource_Inserted(object sender, EntityDataSourceChangedEventArgs e)
    {
        var ex = e.Exception;
    }
}//fM
